﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="manageUser.aspx.cs" Inherits="WebRole1.manageUser" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table>
    <tr>
    <td>
        Current Users:</td>
    <td>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="email" 
        DataSourceID="SqlDataSource1">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="email" HeaderText="email" ReadOnly="True" 
                SortExpression="email" />
            <asp:BoundField DataField="password" HeaderText="password" 
                SortExpression="password" />
            <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConflictDetection="CompareAllValues" 
        ConnectionString="<%$ ConnectionStrings:dbConnection %>" 
        DeleteCommand="DELETE FROM [UserAccount] WHERE [email] = @original_email AND [password] = @original_password AND [name] = @original_name" 
        InsertCommand="INSERT INTO [UserAccount] ([email], [password], [name]) VALUES (@email, @password, @name)" 
        OldValuesParameterFormatString="original_{0}" 
        SelectCommand="SELECT * FROM [UserAccount]" 
        UpdateCommand="UPDATE [UserAccount] SET [password] = @password, [name] = @name WHERE [email] = @original_email AND [password] = @original_password AND [name] = @original_name">
        <DeleteParameters>
            <asp:Parameter Name="original_email" Type="String" />
            <asp:Parameter Name="original_password" Type="String" />
            <asp:Parameter Name="original_name" Type="String" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="email" Type="String" />
            <asp:Parameter Name="password" Type="String" />
            <asp:Parameter Name="name" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="password" Type="String" />
            <asp:Parameter Name="name" Type="String" />
            <asp:Parameter Name="original_email" Type="String" />
            <asp:Parameter Name="original_password" Type="String" />
            <asp:Parameter Name="original_name" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>
    </td>
    </tr>
    <tr>
    <td colspan="2" style="text-align: center">
        Insert new Users at <a href="register.aspx">register</a>. It is not working here</td>
    </tr>
    <tr>
    <td>
    </td>
    <td>
    </td>
    </tr>
    <tr>
    <td>
        Roles Available:</td>
    <td>
        <asp:GridView ID="GridView2" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="uid" 
            DataSourceID="SqlDataSource2">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="uid" HeaderText="uid" InsertVisible="False" 
                    ReadOnly="True" SortExpression="uid" />
                <asp:BoundField DataField="userType" HeaderText="userType" 
                    SortExpression="userType" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConflictDetection="CompareAllValues" 
            ConnectionString="<%$ ConnectionStrings:dbConnection %>" 
            DeleteCommand="DELETE FROM [roles] WHERE [uid] = @original_uid AND [userType] = @original_userType" 
            InsertCommand="INSERT INTO [roles] ([userType]) VALUES (@userType)" 
            OldValuesParameterFormatString="original_{0}" 
            SelectCommand="SELECT * FROM [roles]" 
            UpdateCommand="UPDATE [roles] SET [userType] = @userType WHERE [uid] = @original_uid AND [userType] = @original_userType">
            <DeleteParameters>
                <asp:Parameter Name="original_uid" Type="Int32" />
                <asp:Parameter Name="original_userType" Type="String" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="userType" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="userType" Type="String" />
                <asp:Parameter Name="original_uid" Type="Int32" />
                <asp:Parameter Name="original_userType" Type="String" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </td>
    </tr>
    <tr>
    <td>
        Insert new role:</td>
    <td>
        <asp:FormView ID="FormView2" runat="server" DataKeyNames="uid" 
            DataSourceID="SqlDataSource2" DefaultMode="Insert">
            <EditItemTemplate>
                uid:
                <asp:Label ID="uidLabel1" runat="server" Text='<%# Eval("uid") %>' />
                <br />
                userType:
                <asp:TextBox ID="userTypeTextBox" runat="server" 
                    Text='<%# Bind("userType") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
                userType:
                <asp:TextBox ID="userTypeTextBox" runat="server" 
                    Text='<%# Bind("userType") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                uid:
                <asp:Label ID="uidLabel" runat="server" Text='<%# Eval("uid") %>' />
                <br />
                userType:
                <asp:Label ID="userTypeLabel" runat="server" Text='<%# Bind("userType") %>' />
                <br />
                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" 
                    CommandName="Edit" Text="Edit" />
                &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" 
                    CommandName="Delete" Text="Delete" />
                &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                    CommandName="New" Text="New" />
            </ItemTemplate>
        </asp:FormView>
    </td>
    </tr>
    <tr>
    <td>
        &nbsp;</td>
    <td>
        &nbsp;</td>
    </tr>
    <tr>
    <td>
        Current Role Assigned:</td>
    <td>
        <asp:GridView ID="GridView3" runat="server" 
            AutoGenerateColumns="False" DataKeyNames="userAccount,roles" 
            DataSourceID="SqlDataSource3">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" />
                <asp:BoundField DataField="userAccount" HeaderText="userAccount" 
                    ReadOnly="True" SortExpression="userAccount" />
                <asp:BoundField DataField="roles" HeaderText="roles" ReadOnly="True" 
                    SortExpression="roles" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConflictDetection="CompareAllValues" 
            ConnectionString="<%$ ConnectionStrings:dbConnection %>" 
            DeleteCommand="DELETE FROM [user_roles] WHERE [userAccount] = @original_userAccount AND [roles] = @original_roles" 
            InsertCommand="INSERT INTO [user_roles] ([userAccount], [roles]) VALUES (@userAccount, @roles)" 
            OldValuesParameterFormatString="original_{0}" 
            SelectCommand="SELECT * FROM [user_roles]">
            <DeleteParameters>
                <asp:Parameter Name="original_userAccount" Type="String" />
                <asp:Parameter Name="original_roles" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="userAccount" Type="String" />
                <asp:Parameter Name="roles" Type="Int32" />
            </InsertParameters>
        </asp:SqlDataSource>
    </td>
    </tr>
    <tr>
    <td>
        Assign Role:</td>
    <td>
        <asp:FormView ID="FormView3" runat="server" 
            DataKeyNames="userAccount,roles" DataSourceID="SqlDataSource3" 
            DefaultMode="Insert">
            <EditItemTemplate>
                userAccount:
                <asp:Label ID="userAccountLabel1" runat="server" 
                    Text='<%# Eval("userAccount") %>' />
                <br />
                roles:
                <asp:Label ID="rolesLabel1" runat="server" Text='<%# Eval("roles") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
                userAccount:
                <asp:TextBox ID="userAccountTextBox" runat="server" 
                    Text='<%# Bind("userAccount") %>' />
                <br />
                roles:
                <asp:TextBox ID="rolesTextBox" runat="server" Text='<%# Bind("roles") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                userAccount:
                <asp:Label ID="userAccountLabel" runat="server" 
                    Text='<%# Eval("userAccount") %>' />
                <br />
                roles:
                <asp:Label ID="rolesLabel" runat="server" Text='<%# Eval("roles") %>' />
                <br />
                <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" 
                    CommandName="Delete" Text="Delete" />
                &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                    CommandName="New" Text="New" />
            </ItemTemplate>
        </asp:FormView>
    </td>
    </tr>
    </table>
    </asp:Content>
